
import 'package:huxiaodui/main.dart';
import 'package:flutter/material.dart';
import 'package:huxiaodui/utils/global_controller.dart';
import 'package:huxiaodui/view/pop_pages/alarm_push.dart';
import 'package:huxiaodui/view/index/self_page.dart';
import 'package:huxiaodui/view/index/map_page/map_page.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  HomePageState createState() => HomePageState();
}

class HomePageState extends State<HomePage> {
  PackageInfo? packageInfo;
  @override
  void initState() {
    super.initState();
    getPackageInfo();
  }

  getPackageInfo() async {
    packageInfo = await PackageInfo.fromPlatform();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    var global = Provider.of<GlobalController>(context);

    return Scaffold(
      key: scaffoldKey,
      appBar: AppBar(
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(packageInfo?.appName ?? ""),
            Row(
              children: [
                Visibility(
                  visible: global.user != null,
                  child: IconButton(
                    onPressed: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => const AlarmPush()),
                      );
                    },
                    icon: const Icon(Icons.alarm_add),
                  ),
                ),
              ],
            )
          ],
        ),
      ),
      /* 主页面 */
      body: const MapPage(),
      /* 左边弹出的页面 */
      drawer: const SelfPage(),
    );
  }
}
